package com.simen.hellobytes.regular;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * author: SimenHi
 * create time: 2020-08-20 16:14
 * description:
 */
public class RegularUtil {

    public static boolean isValidEmail(CharSequence email) {
        return isValidEmail(email, false);
    }

    public static boolean isValidEmail(CharSequence email, boolean containsChinese) {
        return match(email, containsChinese ? CommonPattern.PATTERN_EMAIL_WITHCHINESENAME : CommonPattern.PATTERN_EMAIL);
    }

    public static boolean isOnlyUpperLetterWithNumber(CharSequence text) {
        return match(text, CommonPattern.PATTERN_UPPERLETTER_NUMBER);
    }

    public static boolean isOnlyLetterWithNumber(CharSequence text) {
        return match(text, CommonPattern.PATTERN_LETTER_NUMBER);
    }

    public static boolean match(CharSequence text, String patternStr) {
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(text);
        return matcher.matches();
    }
}
